#include <avz.h>

using namespace AvZ;

void Script()
{
    // SetErrorMode(CONSOLE);

    SetZombies({
        ZOMBIE,
        POLE_VAULTING_ZOMBIE,
        FOOTBALL_ZOMBIE,
        DANCING_ZOMBIE,
        ZOMBONI,
        JACK_IN_THE_BOX_ZOMBIE,
        DIGGER_ZOMBIE,
        POGO_ZOMBIE,
        BUNGEE_ZOMBIE,
        LADDER_ZOMBIE,
        CATAPULT_ZOMBIE,
        GARGANTUAR,
        GIGA_GARGANTUAR,
        DOLPHIN_RIDER_ZOMBIE,
        SNORKEL_ZOMBIE,
    });

    SelectCards({
        ICE_SHROOM,
        M_ICE_SHROOM,
        COFFEE_BEAN,
        PUMPKIN,
        PUFF_SHROOM,
        SUN_SHROOM,
        SCAREDY_SHROOM,
        FLOWER_POT,
        CHERRY_BOMB,
        WALL_NUT,
    });

    SetTime(-599, 1);
    pao_operator.resetPaoList({
        {1, 1},
        {2, 1},
        {3, 1},
        {4, 1},
        {5, 1},
        {6, 1},
        {1, 3},
        {2, 3},
        {3, 3},
        {4, 3},
        {5, 3},
        {6, 3},
        {1, 5},
        {2, 5},
        {3, 5},
        {4, 5},
        {5, 5},
        {6, 5},
        {1, 7},
        {2, 7},
        {5, 7},
        {6, 7},
    });

    ice_filler.start({{3, 9}, {4, 9}});

    plant_fixer.start(PUMPKIN);
    plant_fixer.resetFixHp(4000 * 1 / 3);

    for (auto wave : {1, 3, 5, 7, 12, 14, 16, 18})
    {
        // PSD/BDcc 601;
        // BDcc
        SetTime(240 - 373, wave);
        // 引信延迟
        if (wave == 1)
        {
            Delay(-3);
        }
        else if (wave == 14)
        {
            Delay(20);
        }
        pao_operator.pao(5, 9);
        delay(125);
        pao_operator.pao(5, 8.125);
        SetTime(699 - 180);
        Card({{PUFF_SHROOM, 5, 9}, {SUN_SHROOM, 6, 9}});
        Delay(5);
        Shovel({{5, 9}, {6, 9}});

        // PSD
        SetTime(274 - 373);
        pao_operator.pao({{2, 9}, {2, 9}});
        Delay(125);
        if (wave == 14)
        {
            // w10收蹦极炮的复用
            Delay(4);
        }
        pao_operator.pao(1, 8.4);

        SetTime(601 + 100 - 100 - 198);
        ice_filler.coffee();
    }

    for (auto wave : {2, 4, 6, 8, 11, 13, 15, 17})
    {
        // IPP-PD虚/PD实 1149
        SetTime(789 - 601 - 373, wave);
        pao_operator.pao(2, 8.7125);
        SetTime(437 - 373, wave);
        pao_operator.pao(5, 7.4);

        SetTime(1149 - 200 - 373);
        pao_operator.pao({{2, 9}, {5, 9}});
        Delay(220);
        if (wave == 13)
        {
            Delay(10);
        }
        pao_operator.pao({{1, 7.975}, {5, 8.4125}});
    }

    for (auto wave : {9})
    {
        // PSD/BDcc-I-P-PDcccc……
        // BDcc
        SetTime(240 - 373, wave);
        pao_operator.pao(5, 9);
        delay(125);
        pao_operator.pao(5, 8.125);

        SetTime(699 - 180);
        Card({{PUFF_SHROOM, 5, 9}, {SUN_SHROOM, 6, 9}});
        Delay(5);
        Shovel({{5, 9}, {6, 9}});

        // PSD
        SetTime(274 - 373);
        pao_operator.pao({{2, 9}, {2, 9}});
        Delay(125);
        pao_operator.pao(1, 9);

        // I-
        SetTime(701 - 100 - 198);
        ice_filler.coffee();

        //-P炸下半场撑杆
        SetTime(789 - 373);
        pao_operator.pao(5, 7.1125);

        //-PD
        SetTime(1357 - 373);
        pao_operator.pao(5, 9);
        Delay(224);
        pao_operator.pao(5, 9);

        SetTime(4500 - 200 - 373);
        pao_operator.pao({{2, 9}, {5, 9}});
    }

    for (auto wave : {10})
    {
        // PSA/BDcc-P 601;
        // BDcc
        SetTime(240 + 45 - 376, wave);
        pao_operator.pao(5, 9);
        Delay(125);
        pao_operator.pao(5, 8.0375);
        SetTime(699 - 180);
        Card({{PUFF_SHROOM, 5, 9}, {SUN_SHROOM, 6, 9}});
        Delay(5);
        Shovel({{5, 9}, {6, 9}});

        // PSA
        SetTime(274 - 376);
        pao_operator.pao({{2, 9}, {1, 9}});
        SetTime(274 + 108 - 100);
        Card(CHERRY_BOMB, 1, 9);

        // PP收蹦极
        SetTime(394 - 373);
        pao_operator.pao(3, 8);

        SetTime(601 + 100 - 100 - 198);
        ice_filler.coffee();
    }

    for (auto wave : {19})
    {
        // IPP-PPDD-PPDD……
        SetTime(789 - 601 - 373, wave);
        pao_operator.pao(2, 8.7125);
        SetTime(437 - 373, wave);
        pao_operator.pao(5, 7.4);

        SetTime(1149 - 200 - 373);
        pao_operator.pao({{2, 9}, {5, 9}});
        Delay(220);
        pao_operator.pao({{1, 7.975}, {5, 7.975}});

        SetTime(1149 + 274 - 373);
        pao_operator.pao({{2, 8.4625}, {5, 8.4625}});
        Delay(220);
        pao_operator.pao({{1, 8.3125}, {5, 8.3125}});

        SetTime(4500 - 200 - 373);
        pao_operator.pao({{2, 9}, {5, 9}});
    }

    SetTime(-150, 20);
    pao_operator.pao(4, 7.5875);
    SetTime(-55);
    pao_operator.pao({{2, 9}, {5, 9}, {2, 9}, {5, 9}});
    Delay(125);
    pao_operator.pao({{1, 9}, {5, 9}});
    SetTime(409 - 373);
    pao_operator.pao({{2, 9}, {5, 9}});
    SetTime(5500 - 373);
    pao_operator.pao({{2, 9}, {5, 9}});
}